#!/usr/bin/python3
# -*- coding: utf-8 -*-

import json
import xml2dict


class DatabaseSetting():
    def __init__(self):
        self.type = None
        self.ip = None
        self.port = 0

    def parse_db(self, db):
        db_type = None

 #      print('\nDatabaseSetting dump:')
 #      print(json.dumps(db, indent=4))

        if 'type' in db:
            db_type = db['type']
        elif '@type' in db:
            db_type = db['@type']
        else:
            raise
        self.type = db_type

        if 'ip' in db:
            db_ip = db['ip']
        elif '@ip' in db:
            db_ip = db['@ip']
        else:
            raise
        self.ip = db_ip

        if 'port' in db:
            db_port = db['port']
        elif '@port' in db:
            db_port = db['@port']
        else:
            raise
        self.port = int(db_port)

        print('DB type=%s ip=%s port=%d' % (self.type, self.ip, self.port))

        if db_type == 'redis':
            self.parse_redis_db(db)

    def parse_redis_db(self, db):
        pass
